package com.ruoyi.web.controller.system;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.system.domain.WcImgDetail;
import com.ruoyi.system.dto.WcImgPathEx;
import com.ruoyi.system.service.IWcImgDetailService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.WcImgPath;
import com.ruoyi.system.service.IWcImgPathService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2020-03-26
 */
@Controller
@RequestMapping("/system/imgPath")
public class WcImgPathController extends BaseController
{
    private String prefix = "system/imgPath";

    @Autowired
    private IWcImgPathService wcImgPathService;

    @RequiresPermissions("system:path:view")
    @GetMapping()
    public String path()
    {
        return prefix + "/path";
    }

    /**
     * 查询【请填写功能名称】列表
     */
//    @RequiresPermissions("system:path:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(@RequestBody WcImgPath wcImgPath)
    {
        startPage();
        List<WcImgPath> list = wcImgPathService.selectWcImgPathList(wcImgPath);
        List<WcImgPathEx> list2 = wcImgPathService.genImageList(list);

        return getDataTable(list2);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @RequiresPermissions("system:path:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WcImgPath wcImgPath)
    {
        List<WcImgPath> list = wcImgPathService.selectWcImgPathList(wcImgPath);
        ExcelUtil<WcImgPath> util = new ExcelUtil<WcImgPath>(WcImgPath.class);
        return util.exportExcel(list, "path");
    }

    /**
     * 新增【请填写功能名称】
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存【请填写功能名称】
     */
    @RequiresPermissions("system:path:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WcImgPath wcImgPath)
    {
        return toAjax(wcImgPathService.insertWcImgPath(wcImgPath));
    }

    /**
     * 修改【请填写功能名称】
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        WcImgPath wcImgPath = wcImgPathService.selectWcImgPathById(id);
        mmap.put("wcImgPath", wcImgPath);
        return prefix + "/edit";
    }

    /**
     * 修改保存【请填写功能名称】
     */
    @RequiresPermissions("system:path:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WcImgPath wcImgPath)
    {
        return toAjax(wcImgPathService.updateWcImgPath(wcImgPath));
    }

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("system:path:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wcImgPathService.deleteWcImgPathByIds(ids));
    }
}
